home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / libelf / elf.z / elf
Encoding:
Text File  |  1998-10-30  |  20.5 KB  |  337 lines

  1.  
  2.  
  3.  
  4. EEEELLLLFFFF((((3333EEEE))))                                                                EEEELLLLFFFF((((3333EEEE))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      _eeee_llll_ffff - object file access library
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.      _cccc_cccc [_f_l_a_g ...] _f_i_l_e ...  _----_llll_eeee_llll_ffff [_l_i_b_r_a_r_y ...]
  13.      _####_iiii_nnnn_cccc_llll_uuuu_dddd_eeee _<<<<_llll_iiii_bbbb_eeee_llll_ffff_...._hhhh_>>>>
  14.  
  15. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  16.      Functions in the ELF access library let a program manipulate ELF
  17.      (Executable and Linking Format) object files, archive files, and archive
  18.      members.  The header file provides type and function declarations for all
  19.      library services.
  20.  
  21.      Programs communicate with many of the higher-level routines using an _E_L_F
  22.      _d_e_s_c_r_i_p_t_o_r.  That is, when the program starts working with a file,
  23.      _eeee_llll_ffff______bbbb_eeee_gggg_iiii_nnnn creates an ELF descriptor through which the program manipulates
  24.      the structures and information in the file.  These ELF descriptors can be
  25.      used both to read and to write files.  After the program establishes an
  26.      ELF descriptor for a file, it may then obtain _s_e_c_t_i_o_n _d_e_s_c_r_i_p_t_o_r_s to
  27.      manipulate the sections of the file [see _eeee_llll_ffff______gggg_eeee_tttt_ssss_cccc_nnnn(3E)].  Sections hold
  28.      the bulk of an object file's real information, such as text, data, the
  29.      symbol table, and so on.  A section descriptor ``belongs'' to a
  30.      particular ELF descriptor, just as a section belongs to a file.  Finally,
  31.      _d_a_t_a _d_e_s_c_r_i_p_t_o_r_s are available through section descriptors, allowing the
  32.      program to manipulate the information associated with a section.  A data
  33.      descriptor ``belongs'' to a section descriptor.
  34.  
  35.      Descriptors provide private handles to a file and its pieces.  In other
  36.      words, a data descriptor is associated with one section descriptor, which
  37.      is associated with one ELF descriptor, which is associated with one file.
  38.      Although descriptors are private, they give access to data that may be
  39.      shared.  Consider programs that combine input files, using incoming data
  40.      to create or update another file.  Such a program might get data
  41.      descriptors for an input and an output section.  It then could update the
  42.      output descriptor to reuse the input descriptor's data.  That is, the
  43.      descriptors are distinct, but they could share the associated data bytes.
  44.      This sharing avoids the space overhead for duplicate buffers and the
  45.      performance overhead for copying data unnecessarily.
  46.  
  47. FFFFIIIILLLLEEEE CCCCLLLLAAAASSSSSSSSEEEESSSS
  48.      ELF provides a framework in which to define a family of object files,
  49.      supporting multiple processors and architectures.  An important
  50.      distinction among object files is the _c_l_a_s_s, or capacity, of the file.
  51.      The 32-bit class supports architectures in which a 32-bit object can
  52.      represent addresses, file sizes, etc., as in the following.
  53.                           Name                Purpose
  54.                       _______________________________________
  55.                       _EEEE_llll_ffff_3333_2222______AAAA_dddd_dddd_rrrr      Unsigned address
  56.                       _EEEE_llll_ffff_3333_2222______HHHH_aaaa_llll_ffff      Unsigned medium integer
  57.                       _EEEE_llll_ffff_3333_2222______OOOO_ffff_ffff       Unsigned file offset
  58.                                     ||||
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.                                                                         PPPPaaaaggggeeee 1111
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72. EEEELLLLFFFF((((3333EEEE))))                                                                EEEELLLLFFFF((((3333EEEE))))
  73.  
  74.  
  75.  
  76.                       _EEEE_llll_ffff_3333_2222______SSSS_wwww_oooo_rrrr_dddd     Signed large integer
  77.                       _EEEE_llll_ffff_3333_2222______WWWW_oooo_rrrr_dddd      Unsigned large integer
  78.                       _uuuu_nnnn_ssss_iiii_gggg_nnnn_eeee_dddd _cccc_hhhh_aaaa_rrrr   Unsigned small integer
  79.                       _______________________________________
  80.                                     ||||
  81.  
  82.  
  83.  
  84.      Other classes will be defined as necessary, to support larger (or
  85.      smaller) machines.  Some library services deal only with data objects for
  86.      a specific class, while others are class-independent.  To make this
  87.      distinction clear, library function names reflect their status, as
  88.      described below.
  89.  
  90. DDDDAAAATTTTAAAA RRRREEEEPPPPRRRREEEESSSSEEEENNNNTTTTAAAATTTTIIIIOOOONNNNSSSS
  91.      Conceptually, two parallel sets of objects support cross compilation
  92.      environments.  One set corresponds to file contents, while the other set
  93.      corresponds to the native memory image of the program manipulating the
  94.      file.  Type definitions supplied by the header files work on the native
  95.      machine, which may have different data encodings (size, byte order, etc.)
  96.      than the target machine.  Although native memory objects should be at
  97.      least as big as the file objects (to avoid information loss), they may be
  98.      bigger if that is more natural for the host machine.
  99.  
  100.      Translation facilities exist to convert between file and memory
  101.      representations.  Some library routines convert data automatically, while
  102.      others leave conversion as the program's responsibility.  Either way,
  103.      programs that create object files must write file-typed objects to those
  104.      files; programs that read object files must take a similar view.  See
  105.      _eeee_llll_ffff______xxxx_llll_aaaa_tttt_eeee(3E) and _eeee_llll_ffff______ffff_ssss_iiii_zzzz_eeee(3E) for more information.
  106.  
  107.      Programs may translate data explicitly, taking full control over the
  108.      object file layout and semantics.  If the program prefers not to have and
  109.      exercise complete control, the library provides a higher-level interface
  110.      that hides many object file details.  _eeee_llll_ffff______bbbb_eeee_gggg_iiii_nnnn and related functions let
  111.      a program deal with the native memory types, converting between memory
  112.      objects and their file equivalents automatically when reading or writing
  113.      an object file.
  114.  
  115. EEEELLLLFFFF VVVVEEEERRRRSSSSIIIIOOOONNNNSSSS
  116.      Object file versions allow ELF to adapt to new requirements.  Three-
  117.      independent-versions can be important to a program.  First, an
  118.      application program knows about a particular version by virtue of being
  119.      compiled with certain header files.  Second, the access library similarly
  120.      is compiled with header files that control what versions it understands.
  121.      Third, an ELF object file holds a value identifying its version,
  122.      determined by the ELF version known by the file's creator.  Ideally, all
  123.      three versions would be the same, but they may differ.
  124.  
  125.           If a program's version is newer than the access library, the program
  126.           might use information unknown to the library.  Translation routines
  127.           might not work properly, leading to undefined behavior.  This
  128.           condition merits installing a new library.
  129.  
  130.  
  131.  
  132.  
  133.  
  134.                                                                         PPPPaaaaggggeeee 2222
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141. EEEELLLLFFFF((((3333EEEE))))                                                                EEEELLLLFFFF((((3333EEEE))))
  142.  
  143.  
  144.  
  145.           The library's version might be newer than the program's and the
  146.           file's.  The library understands old versions, thus avoiding
  147.           compatibility problems in this case.
  148.  
  149.           Finally, a file's version might be newer than either the program or
  150.           the library understands.  The program might or might not be able to
  151.           process the file properly, depending on whether the file has extra
  152.           information and whether that information can be safely ignored.
  153.           Again, the safe alternative is to install a new library that
  154.           understands the file's version.
  155.  
  156.      To accommodate these differences, a program must use _eeee_llll_ffff______vvvv_eeee_rrrr_ssss_iiii_oooo_nnnn to pass
  157.      its version to the library, thus establishing the _w_o_r_k_i_n_g _v_e_r_s_i_o_n for the
  158.      process.  Using this, the library accepts data from and presents data to
  159.      the program in the proper representations.  When the library reads object
  160.      files, it uses each file's version to interpret the data.  When writing
  161.      files or converting memory types to the file equivalents, the library
  162.      uses the program's working version for the file data.
  163.  
  164. SSSSYYYYSSSSTTTTEEEEMMMM SSSSEEEERRRRVVVVIIIICCCCEEEESSSS
  165.      As mentioned above, _eeee_llll_ffff______bbbb_eeee_gggg_iiii_nnnn and related routines provide a higher-level
  166.      interface to ELF files, performing input and output on behalf of the
  167.      application program.  These routines assume a program can hold entire
  168.      files in memory, without explicitly using temporary files.  When reading
  169.      a file, the library routines bring the data into memory and perform
  170.      subsequent operations on the memory copy.  Programs that wish to read or
  171.      write large object files with this model must execute on a machine with a
  172.      large process virtual address space.  If the underlying operating system
  173.      limits the number of open files, a program can use _eeee_llll_ffff______cccc_nnnn_tttt_llll to retrieve
  174.      all necessary data from the file, allowing the program to close the file
  175.      descriptor and reuse it.
  176.  
  177.      Although the _eeee_llll_ffff______bbbb_eeee_gggg_iiii_nnnn interfaces are convenient and efficient for many
  178.      programs, they might be inappropriate for some.  In those cases, an
  179.      application may invoke the _eeee_llll_ffff______xxxx_llll_aaaa_tttt_eeee data translation routines directly.
  180.      These routines perform no input or output, leaving that as the
  181.      application's responsibility.  By assuming a larger share of the job, an
  182.      application controls its input and output model.
  183.  
  184. LLLLIIIIBBBBRRRRAAAARRRRYYYY NNNNAAAAMMMMEEEESSSS
  185.      Names associated with the library take several forms.
  186.  
  187.      _eeee_llll_ffff______n_a_m_e        These class-independent names perform some service, _n_a_m_e,
  188.                      for the program.
  189.  
  190.      _eeee_llll_ffff_3333_2222______n_a_m_e      Service names with an embedded class, _3333_2222 here, indicate
  191.                      they work only for the designated class of files.
  192.  
  193.      _EEEE_llll_ffff______T_y_p_e        Data types can be class-independent as well,
  194.                      distinguished by _T_y_p_e.
  195.  
  196.  
  197.  
  198.  
  199.  
  200.                                                                         PPPPaaaaggggeeee 3333
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207. EEEELLLLFFFF((((3333EEEE))))                                                                EEEELLLLFFFF((((3333EEEE))))
  208.  
  209.  
  210.  
  211.      _EEEE_llll_ffff_3333_2222______T_y_p_e      Class-dependent data types have an embedded class name,
  212.                      _3333_2222 here.
  213.  
  214.      _EEEE_LLLL_FFFF______CCCC______C_M_D       Several functions take commands that control their
  215.                      actions.  These values are members of the _EEEE_llll_ffff______CCCC_mmmm_dddd
  216.                      enumeration; they range from zero through _EEEE_LLLL_FFFF______CCCC______NNNN_UUUU_MMMM_----_1111.
  217.  
  218.      _EEEE_LLLL_FFFF______FFFF______F_L_A_G      Several functions take flags that control library status
  219.                      and/or actions.  Flags are bits that may be combined.
  220.  
  221.      _EEEE_LLLL_FFFF_3333_2222______FFFF_SSSS_ZZZZ______T_Y_P_E  These constants give the file sizes in bytes of the basic
  222.                      ELF types for the 32-bit class of files.  See _eeee_llll_ffff______ffff_ssss_iiii_zzzz_eeee
  223.                      for more information.
  224.  
  225.      _EEEE_LLLL_FFFF______KKKK______K_I_N_D      The function _eeee_llll_ffff______kkkk_iiii_nnnn_dddd identifies the _K_I_N_D of file
  226.                      associated with an ELF descriptor.  These values are
  227.                      members of the _EEEE_llll_ffff______KKKK_iiii_nnnn_dddd enumeration; they range from zero
  228.                      through _EEEE_LLLL_FFFF______KKKK______NNNN_UUUU_MMMM_----_1111.
  229.  
  230.      _EEEE_LLLL_FFFF______TTTT______T_Y_P_E      When a service function, such as _eeee_llll_ffff______xxxx_llll_aaaa_tttt_eeee, deals with
  231.                      multiple types, names of this form specify the desired
  232.                      _T_Y_P_E.  Thus, for example, _EEEE_LLLL_FFFF______TTTT______EEEE_HHHH_DDDD_RRRR is directly related
  233.                      to _EEEE_llll_ffff_3333_2222______EEEE_hhhh_dddd_rrrr.  These values are members of the _EEEE_llll_ffff______TTTT_yyyy_pppp_eeee
  234.                      enumeration; they range from zero through _EEEE_LLLL_FFFF______TTTT______NNNN_UUUU_MMMM_----_1111.
  235.  
  236. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  237.      _eeee_llll_ffff______bbbb_eeee_gggg_iiii_nnnn(3E), _eeee_llll_ffff______cccc_nnnn_tttt_llll(3E), _eeee_llll_ffff______eeee_nnnn_dddd(3E), _eeee_llll_ffff______eeee_rrrr_rrrr_oooo_rrrr(3E), _eeee_llll_ffff______ffff_iiii_llll_llll(3E),
  238.      _eeee_llll_ffff______ffff_llll_aaaa_gggg(3E), _eeee_llll_ffff______ffff_ssss_iiii_zzzz_eeee(3E), _eeee_llll_ffff______gggg_eeee_tttt_aaaa_rrrr_hhhh_dddd_rrrr(3E), _eeee_llll_ffff______gggg_eeee_tttt_aaaa_rrrr_ssss_yyyy_mmmm(3E),
  239.      _eeee_llll_ffff______gggg_eeee_tttt_bbbb_aaaa_ssss_eeee(3E), _eeee_llll_ffff______gggg_eeee_tttt_dddd_aaaa_tttt_aaaa(3E), _eeee_llll_ffff______gggg_eeee_tttt_eeee_hhhh_dddd_rrrr(3E), _eeee_llll_ffff______gggg_eeee_tttt_iiii_dddd_eeee_nnnn_tttt(3E),
  240.      _eeee_llll_ffff______gggg_eeee_tttt_pppp_hhhh_dddd_rrrr(3E), _eeee_llll_ffff______gggg_eeee_tttt_ssss_cccc_nnnn(3E), _eeee_llll_ffff______gggg_eeee_tttt_ssss_hhhh_dddd_rrrr(3E), _eeee_llll_ffff______hhhh_aaaa_ssss_hhhh(3E),
  241.      _eeee_llll_ffff______kkkk_iiii_nnnn_dddd(3E), _eeee_llll_ffff______nnnn_eeee_xxxx_tttt(3E), _eeee_llll_ffff______rrrr_aaaa_nnnn_dddd(3E), _eeee_llll_ffff______rrrr_aaaa_wwww_ffff_iiii_llll_eeee(3E),
  242.      _eeee_llll_ffff______ssss_tttt_rrrr_pppp_tttt_rrrr(3E), _eeee_llll_ffff______uuuu_pppp_dddd_aaaa_tttt_eeee(3E), _eeee_llll_ffff______vvvv_eeee_rrrr_ssss_iiii_oooo_nnnn(3E), _eeee_llll_ffff______xxxx_llll_aaaa_tttt_eeee(3E), _aaaa_...._oooo_uuuu_tttt(4)
  243.      _aaaa_rrrr(4)
  244.      The chapter ``Object Files'' in _U_N_I_X _S_Y_S_T_E_M _V _R_E_L_E_A_S_E _4 _P_r_o_g_r_a_m_m_e_r'_s
  245.      _G_u_i_d_e: _A_N_S_I _C _a_n_d _P_r_o_g_r_a_m_m_i_n_g _S_u_p_p_o_r_t _T_o_o_l_s, published by Prentice Hall,
  246.      ISBN 0-13-933706-7.
  247.  
  248. NNNNOOOOTTTTEEEESSSS
  249.      The standard SVR4 _e_l_f man page mentions processor-dependent header files
  250.      with names of the form _<<<<_ssss_yyyy_ssss_////_eeee_llll_ffff______N_A_M_E_...._hhhh_>>>> where _N_A_M_E is a processor name in
  251.      a table, such as _MMMM_3333_2222.  There are no such header files in _I_R_I_X.
  252.  
  253.      A 32-bit application can construct 64-bit binaries using functions
  254.      defined on the above-mentioned man pages.  However the man pages and
  255.      certain books published on SVR4 specifically document fields in the
  256.      Elf_Data structure as long.  This restricts the generated object files
  257.      (even 64-bit object files) to have 32-bit values at most when constructed
  258.      by a 32-bit application. The resulting object file is always 64-bit clean
  259.      (the documented 32-bit fields are only too small during construction of
  260.      the object file, not too small in the object file itself).  This matters,
  261.      for example, in the Fortran compiler where the _b_s_s section might need to
  262.      be greater than 32-bits.  See /usr/include/libelf.h _f_o_r _t_h_e _d_e_f_i_n_i_t_i_o_n(_s)
  263.  
  264.  
  265.  
  266.                                                                         PPPPaaaaggggeeee 4444
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273. EEEELLLLFFFF((((3333EEEE))))                                                                EEEELLLLFFFF((((3333EEEE))))
  274.  
  275.  
  276.  
  277.      _o_f _E_l_f__D_a_t_a.
  278.  
  279.      To overcome this difficulty, the generating application should be
  280.      compiled with the preprocessor flag _LIBELF_XTND_64 defined to all
  281.      compilation units and should link to -lelf_xtnd and -ldwarf_xtnd instead
  282.      of -lelf and -ldwarf.  If  this is done, the definition of the fields in
  283.      the Elf_Data changes to 64 bits.  This change permeates the definition of
  284.      an Elf * (even though the definition of Elf* is opaque to the
  285.      application), requiring the application build to be completely consistent
  286.      and define _LIBELF_XTND_64 everywhere in the application build and to
  287.      link with -lelf_xtnd and -ldwarf_xtnd instead of -lelf and -ldwarf.
  288.  
  289.      It is just possible that by compiling with _LIBELF_XTND_64 visible in
  290.      some compilation units but not others an application could manage to pass
  291.      an _EEEE_llll_ffff _**** or other libelf structure created without _LIBELF_XTND_64 _iiii_nnnn_tttt_oooo _aaaa
  292.      _llll_iiii_bbbb_eeee_llll_ffff _ffff_uuuu_nnnn_cccc_tttt_iiii_oooo_nnnn _cccc_aaaa_llll_llll _cccc_oooo_mmmm_pppp_iiii_llll_eeee_dddd _wwww_iiii_tttt_hhhh ______LLLL_IIII_BBBB_EEEE_LLLL_FFFF______XXXX_TTTT_NNNN_DDDD______6666_4444.  Or vice-versa.  The
  293.      result will surely be chaos.
  294.  
  295.      _LIBELF_XTND_64 is irrelevant to any 64-bit application and the
  296.      -lelf_xtnd and -ldwarf_xtnd are not needed, since 64-bit applications can
  297.      build true 64-bit object files without defining _LIBELF_XTND_64.
  298.  
  299.      Applications which only read 64-bit object files need not use
  300.      _LIBELF_XTND_64 since the section headers, program headers, and data of
  301.      the file have 64-bit fields without _LIBELF_XTND_64 being defined.
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.                                                                         PPPPaaaaggggeeee 5555
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.